import Vue from 'vue'
import Router from 'vue-router'
import iView from 'iview'
Vue.use(iView)
Vue.use(Router)
// 首页
const Home = () => import('../components/Home.vue')
// 汇总数据
const Dashboard = () => import('../components/dashboard/Dashboard.vue')
const Warning = () => import('../components/dashboard/Warning.vue')
// 安全监控
const Vedio = () => import('../components/safe/Vedio.vue')
// 能源监控
const Carbon = () => import('../components/energy/Carbon.vue')
const Contrast = () => import('../components/energy/Contrast.vue')
// 后台配置
const Data = () => import('../components/configure/Data.vue')
const Icon = () => import('../components/configure/icon/Icon.vue')
const Img = () => import('../components/configure/Img.vue')
const Model = () => import('../components/configure/Model.vue')
const SysPic = () => import('../components/configure/SysPic.vue')
const Dict = () => import('../components/configure/Dict.vue')
// 登录
const Login = () => import('../components/login/Login.vue')
const NoFind = () => import('../components/NoFind.vue')
// 其他
const Table = () => import('../components/test/Table.vue')
const Table2 = () => import('../components/test/Table2.vue')
// 终端管理
const DeviceManage = () => import('../components/device/manage/DeviceManage.vue')
const DeviceType = () => import('../components/device/type/DeviceType.vue')
// 空间管理
const Space = () => import('../components/space/Space.vue')
// 测试页面
const My = () => import('../components/space/my.vue')
const Testt = () => import('../components/space/Testt.vue')
const atten = () => import('../components/atten/atten')

let router = new Router({
  mode: 'history',
  routes: [{
    path: '/',
    redirect: '/login' /* 默认路由 */
  }, {
    path: '/login',
    name: 'login',
    component: Login
  }, {
    path: '/home',
    component: Home,
    children: [{
      path: '',
      component: atten
    },{
			  path: 'atten', 
			  component: atten
    },{
    	path:"machWatch",
    	component:()=>import("../components/machWatch/allChina.vue")
    }
    ,{
    	path:"factoryWatch",
    	component:()=>import("../components/machWatch/factory_watch.vue")
    }
    ,{
    	path:"machineWatch",
    	component:()=>import("../components/machWatch/machine_watch.vue")
    },{
    	path:"machineDetail",
    	component:()=>import ("../components/machWatch/machine_detail.vue")
    },{
    	path:"sysWatch",
    	component:()=>import ("../components/sysWatch/sysWatch.vue")
	 },{
    	path:"sysExampMod",
    	component:()=>import ("../components/sysWatch/sysExampMod.vue")
    }
    , {
      path: 'table',
      component: Table
    }, {
      path: 'table2',
      component: Table2
    }, {
      path: 'dashboard',
      component: Dashboard
    }, {
      path: 'vedio',
      component: Vedio
    }, {
      path: 'carbon',
      component: Carbon
    }, {
      path: 'contrast',
      component: Contrast
    }, {
      path: 'data',
      component: Data
    }, {
      path: 'icon',
      component: Icon
    }, {
      path: 'img',
      component: Img
    }, {
      path: 'syspic',
      component: SysPic
    }, {
      path: 'dict',
      component: Dict
    }, {
      path: 'model',
      component: Model
    }, {
      path: 'warning',
      component: Warning
    }, {
      path: 'deviceManage',
      component: DeviceManage
    }, {
      path: 'deviceType',
      component: DeviceType
    }, {
      path: 'space',
      component: Space
    }, {
      path: 'my',
      component: My
    }, {
      path: 'qunee',
      component: Testt
    }]
  }, {
    path: '/404',
    name: 'NoFind',
    component: NoFind
  }, {
    path: '*',
    name: 'other',
    redirect: '/404'
  }]
})
router.beforeEach((to, from, next) => {
  // 加载进度条
  iView.LoadingBar.start()
  /* const nextRoute = ['account', 'order', 'course']
  const auth = store.state.auth
  // 跳转至上述3个页面
  if (nextRoute.indexOf(to.name) >= 0) {
    // 未登录
    if (!store.state.auth.IsLogin) {
      vueRouter.push({ name: 'login' })
    }
  }
  //已登录的情况再去登录页，跳转至首页
  if (to.name === 'login') {
    if (auth.IsLogin) {
      vueRouter.push({ name: 'home' })
    }
  } */
  if (to.path.indexOf('home') > -1) {
    let IsLogin = true
    if (IsLogin) {
      next()
    } else {
      next({ path: '/login' })
    }
  }
  next()
})
router.afterEach(route => {
  // 加载进度条
  iView.LoadingBar.finish()
})
export default router
